package com.wandian.core
{

	public class ClassCreatManager
	{
		import flash.system.ApplicationDomain;
		private static var _appDomain:ApplicationDomain
		public function ClassCreatManager()
		{
		}
		private static var _instance:ClassCreatManager;
		
		public static function get instance():ClassCreatManager
		{
			return _instance||= new ClassCreatManager();
		}
		public function set appDomain(domain:ApplicationDomain):void{
			if(_appDomain==null)_appDomain=ApplicationDomain.currentDomain
			_appDomain=domain;
		}
		public function  creatObject(stylename:String):*{
			var xml:XML=GameXmlManager.instance.getUIStyleXml(stylename)
			return voluation(new (creatClass(xml.@classname)),xml);
		}
		public function  creatClass(classname:String):*{
			var appClass:Object =_appDomain.getDefinition(classname);
			return appClass
		}
		public function voluation(appinstance:Object,xml:XML):Object{
			var attr:XMLList =xml.attributes();
			for each(var item:XML in attr)
			{
				var propname:String = item.name().toString();
				if(appinstance.hasOwnProperty(propname))
				{
					try{
						var value:String = item.toString();
						if(value == "false")
						{
							appinstance[propname] = false;
						}else
						{
							appinstance[propname] = value;
						}
					}catch(e:Error)
					{
						trace("错误:",e.message);
					}
				}
			}
			if(appinstance.upProperty)appinstance.upProperty();
			return appinstance;
		}
	}
}